package weiyao.xinxidasai.DTO;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.http.ResponseEntity;

import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
    private Boolean success;
    private String errorMsg;
    private Object data;
    private Long total;
    private Object additionalInfo; // 附加信息字段
    private Object verificationReport; // 验证报告字段



    // 静态工厂方法
    public static Result ok() {
        return new Result(true, null, null, null, null, null);
    }

    public static Result ok(Object data) {
        return new Result(true, null, data, null, null, null);
    }

    public static Result ok(Object data, Object verificationReport) {
        return new Result(true, null, data, null, null, verificationReport);
    }

    public static Result ok(List<?> data, Long total) {
        return new Result(true, null, data, total, null, null);
    }

    public static Result fail(String errorMsg) {
        return new Result(false, errorMsg, null, null, null, null);
    }

    public static Result fail(String errorMsg, Object data, Object verificationReport) {
        return new Result(false, errorMsg, data, null, null, verificationReport);
    }

    // 链式设置方法
    public Result setData(Object data) {
        this.data = data;
        return this;
    }

    public Result setErrorMsg(String errorMsg) {
        this.errorMsg = errorMsg;
        return this;
    }

    public Result setAdditionalInfo(Object info) {
        this.additionalInfo = info;
        return this;
    }

    public Result setVerificationReport(Object report) {
        this.verificationReport = report;
        return this;
    }

    public Result setTotal(Long total) {
        this.total = total;
        return this;
    }

    // 类型安全的获取方法
    public <T> T getData(Class<T> type) {
        if (data != null && type.isInstance(data)) {
            return type.cast(data);
        }
        return null;
    }

    public <T> T getAdditionalInfo(Class<T> type) {
        if (additionalInfo != null && type.isInstance(additionalInfo)) {
            return type.cast(additionalInfo);
        }
        return null;
    }

    public <T> T getVerificationReport(Class<T> type) {
        if (verificationReport != null && type.isInstance(verificationReport)) {
            return type.cast(verificationReport);
        }
        return null;
    }
}